﻿using System.Web.Mvc;
using SportsStore.Logging;
using SportsStore.ServicesInterfaces;
using SportsStore.ServicesInterfaces.Interfaces;
using SportsStore.Model;
using SportsStore.Web.Models.Product;

namespace SportsStore.Web.Controllers
{
    public class ProductController : BaseController
  {
    private readonly IProductService _productService;
    public int PageSize = 3;

    public ProductController(IProductService productService, ILogger logger)
        : base(logger)
    {
      _productService = productService;
    }

    public ActionResult Index(string category, int page = 1)
    {
      var productsViewModel = new ProductsViewModel();
      PagedResult<Product> products = _productService.GetProducts(page, this.PageSize, category);
      productsViewModel.AddProducts(products);
      productsViewModel.SetCategory(category);
      return View(productsViewModel);
    }
  }
}
